.class Lcom/melesta/engine/AwardsHelper;
.super Ljava/lang/Object;
.source "AwardsHelper.java"


# static fields
.field static mInstance:Lcom/melesta/engine/AwardsHelper;


# instance fields
.field private final mAchivements:Ljava/util/Map;
    .annotation system Ldalvik/annotation/Signature;
        value = {
            "Ljava/util/Map",
            "<",
            "Ljava/lang/String;",
            "Ljava/lang/String;",
            ">;"
        }
    .end annotation
.end field

.field private final mLeaderboards:Ljava/util/Map;
    .annotation system Ldalvik/annotation/Signature;
        value = {
            "Ljava/util/Map",
            "<",
            "Ljava/lang/String;",
            "Ljava/lang/String;",
            ">;"
        }
    .end annotation
.end field


# direct methods
.method static constructor <clinit>()V
    .locals 1

    .prologue
    .line 18
    new-instance v0, Lcom/melesta/engine/AwardsHelper;

    invoke-direct {v0}, Lcom/melesta/engine/AwardsHelper;-><init>()V

    sput-object v0, Lcom/melesta/engine/AwardsHelper;->mInstance:Lcom/melesta/engine/AwardsHelper;

    return-void
.end method

.method private constructor <init>()V
    .locals 1

    .prologue
    .line 28
    invoke-direct {p0}, Ljava/lang/Object;-><init>()V

    .line 20
    new-instance v0, Ljava/util/HashMap;

    invoke-direct {v0}, Ljava/util/HashMap;-><init>()V

    iput-object v0, p0, Lcom/melesta/engine/AwardsHelper;->mAchivements:Ljava/util/Map;

    .line 21
    new-instance v0, Ljava/util/HashMap;

    invoke-direct {v0}, Ljava/util/HashMap;-><init>()V

    iput-object v0, p0, Lcom/melesta/engine/AwardsHelper;->mLeaderboards:Ljava/util/Map;

    .line 29
    return-void
.end method

.method static getHelper()Lcom/melesta/engine/AwardsHelper;
    .locals 1

    .prologue
    .line 25
    sget-object v0, Lcom/melesta/engine/AwardsHelper;->mInstance:Lcom/melesta/engine/AwardsHelper;

    return-object v0
.end method

.method private loadAchievements(Lorg/w3c/dom/Node;)V
    .locals 1
    .parameter "node"

    .prologue
    .line 56
    iget-object v0, p0, Lcom/melesta/engine/AwardsHelper;->mAchivements:Ljava/util/Map;

    invoke-static {v0, p1}, Lcom/melesta/engine/AwardsHelper;->loadKeyValueMap(Ljava/util/Map;Lorg/w3c/dom/Node;)V

    .line 57
    return-void
.end method

.method private static loadKeyValueMap(Ljava/util/Map;Lorg/w3c/dom/Node;)V
    .locals 7
    .parameter
    .parameter "node"
    .annotation system Ldalvik/annotation/Signature;
        value = {
            "(",
            "Ljava/util/Map",
            "<",
            "Ljava/lang/String;",
            "Ljava/lang/String;",
            ">;",
            "Lorg/w3c/dom/Node;",
            ")V"
        }
    .end annotation

    .prologue
    .line 60
    .local p0, map:Ljava/util/Map;,"Ljava/util/Map<Ljava/lang/String;Ljava/lang/String;>;"
    invoke-interface {p0}, Ljava/util/Map;->clear()V

    .line 61
    invoke-interface {p1}, Lorg/w3c/dom/Node;->getChildNodes()Lorg/w3c/dom/NodeList;

    move-result-object v3

    .line 62
    .local v3, items:Lorg/w3c/dom/NodeList;
    const/4 v1, 0x0

    .local v1, i:I
    :goto_0
    invoke-interface {v3}, Lorg/w3c/dom/NodeList;->getLength()I

    move-result v6

    if-ge v1, v6, :cond_1

    .line 63
    invoke-interface {v3, v1}, Lorg/w3c/dom/NodeList;->item(I)Lorg/w3c/dom/Node;

    move-result-object v2

    .line 64
    .local v2, item:Lorg/w3c/dom/Node;
    invoke-interface {v2}, Lorg/w3c/dom/Node;->getAttributes()Lorg/w3c/dom/NamedNodeMap;

    move-result-object v0

    .line 65
    .local v0, attributes:Lorg/w3c/dom/NamedNodeMap;
    if-nez v0, :cond_0

    .line 62
    :goto_1
    add-int/lit8 v1, v1, 0x1

    goto :goto_0

    .line 67
    :cond_0
    const-string v6, "key"

    invoke-interface {v0, v6}, Lorg/w3c/dom/NamedNodeMap;->getNamedItem(Ljava/lang/String;)Lorg/w3c/dom/Node;

    move-result-object v6

    invoke-interface {v6}, Lorg/w3c/dom/Node;->getNodeValue()Ljava/lang/String;

    move-result-object v4

    .line 68
    .local v4, key:Ljava/lang/String;
    const-string v6, "value"

    invoke-interface {v0, v6}, Lorg/w3c/dom/NamedNodeMap;->getNamedItem(Ljava/lang/String;)Lorg/w3c/dom/Node;

    move-result-object v6

    invoke-interface {v6}, Lorg/w3c/dom/Node;->getNodeValue()Ljava/lang/String;

    move-result-object v5

    .line 70
    .local v5, value:Ljava/lang/String;
    invoke-interface {p0, v4, v5}, Ljava/util/Map;->put(Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object;

    goto :goto_1

    .line 72
    .end local v0           #attributes:Lorg/w3c/dom/NamedNodeMap;
    .end local v2           #item:Lorg/w3c/dom/Node;
    .end local v4           #key:Ljava/lang/String;
    .end local v5           #value:Ljava/lang/String;
    :cond_1
    return-void
.end method

.method private loadLeaderboards(Lorg/w3c/dom/Node;)V
    .locals 1
    .parameter "node"

    .prologue
    .line 52
    iget-object v0, p0, Lcom/melesta/engine/AwardsHelper;->mLeaderboards:Ljava/util/Map;

    invoke-static {v0, p1}, Lcom/melesta/engine/AwardsHelper;->loadKeyValueMap(Ljava/util/Map;Lorg/w3c/dom/Node;)V

    .line 53
    return-void
.end method


# virtual methods
.method public getAchievementId(Ljava/lang/String;)Ljava/lang/String;
    .locals 2
    .parameter "id"

    .prologue
    .line 75
    iget-object v1, p0, Lcom/melesta/engine/AwardsHelper;->mAchivements:Ljava/util/Map;

    invoke-interface {v1, p1}, Ljava/util/Map;->get(Ljava/lang/Object;)Ljava/lang/Object;

    move-result-object v0

    check-cast v0, Ljava/lang/String;

    .line 76
    .local v0, res:Ljava/lang/String;
    return-object v0
.end method

.method public getAchievementsIds()Ljava/util/Collection;
    .locals 1
    .annotation system Ldalvik/annotation/Signature;
        value = {
            "()",
            "Ljava/util/Collection",
            "<",
            "Ljava/lang/String;",
            ">;"
        }
    .end annotation

    .prologue
    .line 85
    iget-object v0, p0, Lcom/melesta/engine/AwardsHelper;->mAchivements:Ljava/util/Map;

    invoke-interface {v0}, Ljava/util/Map;->values()Ljava/util/Collection;

    move-result-object v0

    return-object v0
.end method

.method public getLeaderboardId(Ljava/lang/String;)Ljava/lang/String;
    .locals 2
    .parameter "id"

    .prologue
    .line 80
    iget-object v1, p0, Lcom/melesta/engine/AwardsHelper;->mLeaderboards:Ljava/util/Map;

    invoke-interface {v1, p1}, Ljava/util/Map;->get(Ljava/lang/Object;)Ljava/lang/Object;

    move-result-object v0

    check-cast v0, Ljava/lang/String;

    .line 81
    .local v0, res:Ljava/lang/String;
    return-object v0
.end method

.method loadConfig(Ljava/io/InputStream;)V
    .locals 10
    .parameter "xmlStream"

    .prologue
    .line 32
    invoke-static {}, Ljavax/xml/parsers/DocumentBuilderFactory;->newInstance()Ljavax/xml/parsers/DocumentBuilderFactory;

    move-result-object v3

    .line 34
    .local v3, factory:Ljavax/xml/parsers/DocumentBuilderFactory;
    :try_start_0
    invoke-virtual {v3}, Ljavax/xml/parsers/DocumentBuilderFactory;->newDocumentBuilder()Ljavax/xml/parsers/DocumentBuilder;

    move-result-object v0

    .line 35
    .local v0, doc:Ljavax/xml/parsers/DocumentBuilder;
    invoke-virtual {v0, p1}, Ljavax/xml/parsers/DocumentBuilder;->parse(Ljava/io/InputStream;)Lorg/w3c/dom/Document;

    move-result-object v1

    .line 36
    .local v1, dom:Lorg/w3c/dom/Document;
    invoke-interface {v1}, Lorg/w3c/dom/Document;->getDocumentElement()Lorg/w3c/dom/Element;

    move-result-object v7

    .line 37
    .local v7, root:Lorg/w3c/dom/Element;
    invoke-interface {v7}, Lorg/w3c/dom/Element;->getChildNodes()Lorg/w3c/dom/NodeList;

    move-result-object v6

    .line 39
    .local v6, items:Lorg/w3c/dom/NodeList;
    const/4 v4, 0x0

    .local v4, i:I
    :goto_0
    invoke-interface {v6}, Lorg/w3c/dom/NodeList;->getLength()I

    move-result v8

    if-ge v4, v8, :cond_2

    .line 40
    invoke-interface {v6, v4}, Lorg/w3c/dom/NodeList;->item(I)Lorg/w3c/dom/Node;

    move-result-object v5

    .line 41
    .local v5, item:Lorg/w3c/dom/Node;
    invoke-interface {v5}, Lorg/w3c/dom/Node;->getNodeName()Ljava/lang/String;

    move-result-object v8

    const-string v9, "achievements"

    invoke-virtual {v8, v9}, Ljava/lang/String;->equals(Ljava/lang/Object;)Z

    move-result v8

    if-eqz v8, :cond_1

    .line 42
    invoke-direct {p0, v5}, Lcom/melesta/engine/AwardsHelper;->loadAchievements(Lorg/w3c/dom/Node;)V

    .line 39
    :cond_0
    :goto_1
    add-int/lit8 v4, v4, 0x1

    goto :goto_0

    .line 43
    :cond_1
    invoke-interface {v5}, Lorg/w3c/dom/Node;->getNodeName()Ljava/lang/String;

    move-result-object v8

    const-string v9, "leaderboards"

    invoke-virtual {v8, v9}, Ljava/lang/String;->equals(Ljava/lang/Object;)Z

    move-result v8

    if-eqz v8, :cond_0

    .line 44
    invoke-direct {p0, v5}, Lcom/melesta/engine/AwardsHelper;->loadLeaderboards(Lorg/w3c/dom/Node;)V
    :try_end_0
    .catch Ljava/lang/Exception; {:try_start_0 .. :try_end_0} :catch_0

    goto :goto_1

    .line 46
    .end local v0           #doc:Ljavax/xml/parsers/DocumentBuilder;
    .end local v1           #dom:Lorg/w3c/dom/Document;
    .end local v4           #i:I
    .end local v5           #item:Lorg/w3c/dom/Node;
    .end local v6           #items:Lorg/w3c/dom/NodeList;
    .end local v7           #root:Lorg/w3c/dom/Element;
    :catch_0
    move-exception v2

    .line 47
    .local v2, e:Ljava/lang/Exception;
    const/4 v8, 0x0

    invoke-static {v8, v2}, Lcom/melesta/engine/Error;->processException(Ljava/lang/String;Ljava/lang/Exception;)V

    .line 49
    .end local v2           #e:Ljava/lang/Exception;
    :cond_2
    return-void
.end method
